﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace QuanLyPhongKham
{
    public partial class FrmKhamBenh : Form
    {
        string strconnect = "Data Source=CALVINVU\\SQLSERVER;Initial Catalog=QLPK;Persist Security Info=True;User ID=sa;Password=87kvs@07";
        SqlConnection conn = null;
        SqlDataAdapter dathuoc = null;
        DataTable dtthuoc = null;
        SqlDataAdapter datoathuoc = null;
        DataTable dttoathuoc = null;
        //bool Them;

        public FrmKhamBenh()
        {
            InitializeComponent();
        }

        private void btnTrove_Click(object sender, EventArgs e)
        {
            this.Hide();
            FrmChinh Chinh = new FrmChinh();
            Chinh.ShowDialog();
            this.Close();
        }

        private void FrmKhamBenh_Load(object sender, EventArgs e)
        {
            LoadData();
            // TODO: This line of code loads data into the 'qLPKDataSet4.thuoc' table. You can move, or remove it, as needed.
            //this.thuocTableAdapter.Fill(this.qLPKDataSet4.thuoc);
            // TODO: This line of code loads data into the 'qLPKDataSet3.ToaThuoc' table. You can move, or remove it, as needed.
            //this.toaThuocTableAdapter.Fill(this.qLPKDataSet3.ToaThuoc);

        }
        void LoadData()
        {
            try
            {
                conn = new SqlConnection(strconnect);
                dathuoc = new SqlDataAdapter("select * from Thuoc", conn);
                dtthuoc = new DataTable();
                dtthuoc.Clear();
                dathuoc.Fill(dtthuoc);
                dgvthuoc.DataSource = dtthuoc;

                datoathuoc = new SqlDataAdapter("select * from ToaThuoc", conn);
                dttoathuoc = new DataTable();
                dttoathuoc.Clear();
                datoathuoc.Fill(dtthuoc);
                dgvtoathuoc.DataSource = dttoathuoc;

                //this.txtMabn.ResetText();
                this.txtmahs.ResetText();
                this.txtten.ResetText();
                this.txtnamsinh.ResetText();
                this.txtdiachi.ResetText();
                this.txtchandoan.ResetText();
                this.txtmach.ResetText();
                this.txthuyetap.ResetText();
                this.txtduonghuyet.ResetText();
                this.txtSang.ResetText();
                this.txtTrua.ResetText();
                this.txtChieu.ResetText();
                this.txtToi.ResetText();
                this.txtTenhoatchat.ResetText();
                this.txtThuoc.ResetText();

               /* this.BtnLuu.Enabled = false;
                this.btnHuybo.Enabled = false;
                //this.panel.Enabled = false;

                this.btnThem.Enabled = true;
                this.btnSua.Enabled = true;
                this.btnXoa.Enabled = true;
                this.btnTrove.Enabled = true;*/
            }
            catch (SqlException)
            {
                MessageBox.Show("Không lấy được nội dung trong table Thuoc. Lỗi rồi!!!");
            }
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            LoadData();
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch(keyData)
            {                
                case (Keys.Control | Keys.R):
                    btnReload_Click(null, null);
                    break;
                case (Keys.Control | Keys.N):
                    btnThem_Click(null, null);
                    break;
                case (Keys.Control | Keys.H):
                    btnHuybo_Click(null, null);
                    break;
                case (Keys.Control | Keys.S):
                    BtnLuu_Click(null, null);
                    break;
                case (Keys.Control | Keys.E):
                    btnSua_Click(null, null);
                    break;
                case (Keys.Control | Keys.X):
                    btnXoa_Click(null, null);
                    break;
                case (Keys.Control | Keys.T):
                    btnTrove_Click(null, null);
                    break;
            }
            return base.ProcessCmdKey(ref msg, keyData);
    }

        private void btnThem_Click(object sender, EventArgs e)
        {
        
        }

        private void BtnLuu_Click(object sender, EventArgs e)
        {
        
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
        
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
        
        }

        private void btnHuybo_Click(object sender, EventArgs e)
        {
        
        }
    }
}
